home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / amigaunits / timer.pas < prev    next >
Pascal/Delphi Source File  |  2000-01-01  |  3KB  |  149 lines

  1. {
  2.     This file is part of the Free Pascal run time library.
  3.  
  4.     A file in Amiga system run time library.
  5.     Copyright (c) 1998-2000 by Nils Sjoholm
  6.     member of the Amiga RTL development team.
  7.  
  8.     See the file COPYING.FPC, included in this distribution,
  9.     for details about the copyright.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14.  
  15.  **********************************************************************}
  16.  
  17. unit timer;
  18.  
  19. INTERFACE
  20.  
  21. uses exec;
  22.  
  23. Const
  24.  
  25. { unit defintions }
  26.     UNIT_MICROHZ        = 0;
  27.     UNIT_VBLANK         = 1;
  28.     UNIT_ECLOCK         = 2;
  29.     UNIT_WAITUNTIL      = 3;
  30.     UNIT_WAITECLOCK     = 4;
  31.  
  32.     TIMERNAME : PChar   = 'timer.device';
  33.  
  34. Type
  35.  
  36.     ptimeval = ^ttimeval;
  37.     ttimeval = record
  38.         tv_secs         : ULONG;
  39.         tv_micro        : ULONG;
  40.     end;
  41.  
  42.     ptimerequest = ^ttimerequest;
  43.     ttimerequest = record
  44.         tr_node         : tIORequest;
  45.         tr_time         : ttimeval;
  46.     end;
  47.  
  48.     pEClockVal = ^tEClockVal;
  49.     tEClockVal = record
  50.         ev_hi : ULONG;
  51.         ev_lo : ULONG;
  52.     end;
  53.  
  54.  
  55. Const
  56.  
  57. { IO_COMMAND to use for adding a timer }
  58.     TR_ADDREQUEST       = CMD_NONSTD;
  59.     TR_GETSYSTIME       = CMD_NONSTD + 1;
  60.     TR_SETSYSTIME       = CMD_NONSTD + 2;
  61.  
  62. {  To use any of the routines below, TimerBase must be set to point
  63.    to the timer.device, either by calling CreateTimer or by pulling
  64.    the device pointer from a valid TimeRequest, i.e.
  65.  
  66.         TimerBase := TimeRequest.io_Device;
  67.  
  68.     _after_ you have called OpenDevice on the timer.
  69.  }
  70.  
  71. var
  72.     TimerBase   : Pointer;
  73.  
  74. Procedure AddTime(VAR Dest, Source : ptimeval);
  75. Function CmpTime(VAR Dest, Source : ptimeval) : ULONG;
  76. Procedure SubTime(VAR Dest, Source : ptimeval);
  77. function ReadEClock(Dest : pEClockVal): longint;
  78. procedure GetSysTime(Dest : ptimeval);
  79.  
  80. IMPLEMENTATION
  81.  
  82. Procedure AddTime(VAR Dest, Source : ptimeval);
  83. begin
  84.    asm
  85.        MOVE.L  A6,-(A7)
  86.        MOVE.L  Dest,a0
  87.        MOVE.L  Source,a1
  88.        MOVE.L  TimerBase,A6
  89.        JSR -042(A6)
  90.        MOVE.L  (A7)+,A6
  91.    end;
  92. end;
  93.  
  94. Function CmpTime(VAR Dest, Source : ptimeval) : ULONG;
  95. begin
  96.    asm
  97.        MOVE.L  A6,-(A7)
  98.        MOVE.L  Dest,a0
  99.        MOVE.L  Source,a1
  100.        MOVE.L  TimerBase,A6
  101.        JSR -054(A6)
  102.        MOVE.L  (A7)+,A6
  103.        MOVE.L  d0,@RESULT
  104.    end;
  105. end;
  106.  
  107. Procedure SubTime(VAR Dest, Source : ptimeval);
  108. begin
  109.    asm
  110.        MOVE.L  A6,-(A7)
  111.        MOVE.L  Dest,a0
  112.        MOVE.L  Source,a1
  113.        MOVE.L  TimerBase,A6
  114.        JSR -048(A6)
  115.        MOVE.L  (A7)+,A6
  116.    end;
  117. end;
  118.  
  119. function ReadEClock(Dest : pEClockVal): longint;
  120. begin
  121.    asm
  122.        MOVE.L  A6,-(A7)
  123.        MOVE.L  Dest,a0
  124.        MOVE.L  TimerBase,A6
  125.        JSR -060(A6)
  126.        MOVE.L  (A7)+,A6
  127.        MOVE.L  d0,@RESULT
  128.    end;
  129. end;
  130.  
  131. procedure GetSysTime(Dest : ptimeval);
  132. begin
  133.    asm
  134.        MOVE.L  A6,-(A7)
  135.        MOVE.L  Dest,a0
  136.        MOVE.L  TimerBase,A6
  137.        JSR -066(A6)
  138.        MOVE.L  (A7)+,A6
  139.    end;
  140. end;
  141.  
  142.  
  143. end.
  144.  
  145.  
  146.  
  147.  
  148.  
  149.